package com.hq.common.domain;

import com.hq.common.utils.TimeUtil;
import org.apache.commons.lang.StringUtils;


public class SearchValue {

	public enum Pattern {
		IN, LIKE, EQUAL, NOTEQUAL,GT, GE, LT, LE, SQL, NULL, NOTNULL
	}
	public enum DataType {
		INT,LONG,DATE,STRING
	}

	public enum Order {
		ASC, DESC
	}

	private String name;	//查询列名
	private Object value;	//查询列值
	private Order order;	//是否按列排序
	private Pattern pattern;	//条件方式
	private DataType valueType;//列值的类型
	private int orderSeq;		//按钮排序的顺序

	public SearchValue() { }

	public SearchValue(String name, Object value, Pattern pattern){
		this.name = name;
		this.value = value;
		this.pattern = pattern;
	}

	public SearchValue(String name,Order order,int orderSeq){
		this.name = name;
		this.order = order;
		this.orderSeq = orderSeq;
	}

	public boolean isBlank(){

		if(StringUtils.isBlank(name)){	//如果查询列不为空，可能是排序，可能是查询值
			return true;
		}else if(pattern!=Pattern.NOTNULL&&pattern!=Pattern.NULL&&pattern!=Pattern.SQL&&(value==null||StringUtils.isEmpty(value.toString()))){
			return true;
		}
		return false;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		if(valueType ==null||value==null||StringUtils.isEmpty(value.toString())){
			this.value = value;
		}else {
			switch (valueType) {
				case INT:
					this.value = Integer.valueOf(value.toString());
					break;
				case LONG:
					this.value = Long.valueOf(value.toString());
					break;
				case DATE:
					this.value = TimeUtil.parseDateStr(value.toString());
					break;
				default:
					this.value = value;
			}
		}
	}

	public int getOrderSeq() {
		return orderSeq;
	}

	public void setOrderSeq(int seq) {
		this.orderSeq = seq;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public Pattern getPattern() {
		return pattern;
	}

	public void setPattern(Pattern pattern) {
		this.pattern = pattern;
	}

	public DataType getValueType() {
		return valueType;
	}

	public void setValueType(DataType valueType) {
		this.valueType = valueType;
		if(valueType !=null&&value!=null&&StringUtils.isNotEmpty(value.toString())){
			switch (valueType) {
				case INT:
					this.value = Integer.valueOf(value.toString());
					break;
				case LONG:
					this.value = Long.valueOf(value.toString());
					break;
				case DATE:
					this.value = TimeUtil.parseDateStr(value.toString());
					break;
			}
		}
	}
}
